<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<head>
    <title>Jumper documentation</title>
    <link rel="stylesheet" href="../ldoc.css" type="text/css" />
</head>
<body>

<div id="container">

<div id="product">
	<div id="product_logo"></div>
	<div id="product_name"><big><b></b></big></div>
	<div id="product_description"></div>
</div> <!-- id="product" -->


<div id="main">


<!-- Menu -->

<div id="navigation">
<br/>
<h1>Jumper(v1.8.1)</h1>

<ul>
  <li><a href="../index.html">Index</a></li>
</ul>

<h2>Contents</h2>
<ul>
<li><a href="#Functions">Functions</a></li>
</ul>


<h2>Modules</h2>
<ul>
  <li><a href="../modules/jumper.core.bheap.html">jumper.core.bheap</a></li>
  <li><strong>jumper.core.heuristics</strong></li>
  <li><a href="../modules/jumper.core.node.html">jumper.core.node</a></li>
  <li><a href="../modules/jumper.core.path.html">jumper.core.path</a></li>
  <li><a href="../modules/jumper.grid.html">jumper.grid</a></li>
  <li><a href="../modules/jumper.grid.html">jumper.grid</a></li>
  <li><a href="../modules/jumper.pathfinder.html">jumper.pathfinder</a></li>
</ul>
<h2>Scripts</h2>
<ul>
  <li><a href="../scripts/jumper.search.astar.html">jumper.search.astar</a></li>
  <li><a href="../scripts/jumper.search.bfs.html">jumper.search.bfs</a></li>
  <li><a href="../scripts/jumper.search.dfs.html">jumper.search.dfs</a></li>
  <li><a href="../scripts/jumper.search.dijkstra.html">jumper.search.dijkstra</a></li>
  <li><a href="../scripts/jumper.search.jps.html">jumper.search.jps</a></li>
  <li><a href="../scripts/jumper.search.thetastar.html">jumper.search.thetastar</a></li>
</ul>

</div>

<div id="content">

<h1>Module <code>jumper.core.heuristics</code></h1>

<p><strong>Heuristics for the search algorithm</strong>.</p>
<p> A <a href="http://theory.stanford.edu/~amitp/GameProgramming/Heuristics.html">heuristic</a>
 provides an <em>estimate of the optimal cost</em> from a given location to a target.
 As such, it guides the pathfinder to the goal, helping it to decide which route is the best.</p>

<p> This script holds the definition of built-in heuristics available.</p>

<p> Distance functions are internally used by the <a href="../modules/jumper.core.heuristics.html#jumper.pathfinder">pathfinder</a>  to evaluate the optimal path
 from the start location to the goal. These functions share the same prototype:
 <ul>
 <pre class="example">
 local function myHeuristic(dx, dy)
   -- function body
 end
 </pre></ul>
 Jumper features some built-in distance heuristics, named <code>MANHATTAN</code>, <code>EUCLIDIAN</code>, <code>DIAGONAL</code>, <code>CARDINTCARD</code>.
 You can also supply your own heuristic function, using the template given above.</p>
    <h3>Usage:</h3>
    <ul>
        <pre class="example">  -- Example
  local Distance = require (&apos;jumper.core.heuristics&apos;)
  local Grid = require (&quot;jumper.grid&quot;)
  local Pathfinder = require (&quot;jumper.pathfinder&quot;)
  local walkable = 0
  -- Placeholder: local map = {...}
  local grid = Grid(map)
  local myFinder = Pathfinder(&apos;ASTAR&apos;, grid, walkable)

  -- Use Euclidian heuristic to evaluate distance
  myFinder:setHeuristic(&apos;EUCLIDIAN&apos;)
  -- etc ...
</pre>
    </ul>
    <h3>Info:</h3>
    <ul>
        <li><strong>Copyright</strong>: 2012-2013</li>
        <li><strong>License</strong>: MIT</li>
        <li><strong>Author</strong>: Roland Yonaba</li>
    </ul>


<h2><a href="#Functions">Functions</a></h2>
<table class="function_list">
	<tr>
	<td class="name" nowrap><a href="#Heuristics.MANHATTAN">Heuristics.MANHATTAN&nbsp;(dx, dy)</a></td>
	<td class="summary">Manhattan distance.</td>
	</tr>
	<tr>
	<td class="name" nowrap><a href="#Heuristics.EUCLIDIAN">Heuristics.EUCLIDIAN&nbsp;(dx, dy)</a></td>
	<td class="summary">Euclidian distance.</td>
	</tr>
	<tr>
	<td class="name" nowrap><a href="#Heuristics.DIAGONAL">Heuristics.DIAGONAL&nbsp;(dx, dy)</a></td>
	<td class="summary">Diagonal distance.</td>
	</tr>
	<tr>
	<td class="name" nowrap><a href="#Heuristics.CARDINTCARD">Heuristics.CARDINTCARD&nbsp;(dx, dy)</a></td>
	<td class="summary">Cardinal/Intercardinal distance.</td>
	</tr>
</table>

<br/>
<br/>


    <h2><a name="Functions"></a>Functions</h2>

    <dl class="function">
    <dt>
    <a name = "Heuristics.MANHATTAN"></a>
    <strong>Heuristics.MANHATTAN&nbsp;(dx, dy)</strong>
    </dt>
    <dd>
    Manhattan distance.
 <br/>This heuristic is the default one being used by the <a href="../modules/jumper.core.heuristics.html#jumper.pathfinder">pathfinder</a>  object.
 <br/>Evaluates as <code>distance = |dx|+|dy|</code>

    <h3>Parameters:</h3>
    <ul>
      <li><span class="parameter">dx</span>
        <span class="types"><span class="type">int</span></span>
       the difference endX-startX</li>
      <li><span class="parameter">dy</span>
        <span class="types"><span class="type">int</span></span>
       the difference endY-startY</li>
    </ul>

    <h3>Returns:</h3>
    <ol>

          <span class="types"><span class="type">number</span></span>
        the distance from location <code>startX, startY</code> to location <code>endX, endY</code>
 <ul>
 <pre class="example">
 -- First method
 pathfinder:setHeuristic('MANHATTAN')<br/>
 -- Second method
 local Distance = require ('jumper.core.heuristics')
 pathfinder:setHeuristic(Distance.MANHATTAN)
 </pre></ul>
    </ol>




</dd>
    <dt>
    <a name = "Heuristics.EUCLIDIAN"></a>
    <strong>Heuristics.EUCLIDIAN&nbsp;(dx, dy)</strong>
    </dt>
    <dd>
    Euclidian distance.
 <br/>Evaluates as <code>distance = squareRoot(dx*dx+dy*dy)</code>

    <h3>Parameters:</h3>
    <ul>
      <li><span class="parameter">dx</span>
        <span class="types"><span class="type">int</span></span>
       the difference endX-startX</li>
      <li><span class="parameter">dy</span>
        <span class="types"><span class="type">int</span></span>
       the difference endY-startY</li>
    </ul>

    <h3>Returns:</h3>
    <ol>

          <span class="types"><span class="type">number</span></span>
        the distance from location <code>startX, startY</code> to location <code>endX, endY</code>
 <ul>
 <pre class="example">
 -- First method
 pathfinder:setHeuristic('EUCLIDIAN')<br/>
 -- Second method
 local Distance = require ('jumper.core.heuristics')
 pathfinder:setHeuristic(Distance.EUCLIDIAN)
 </pre></ul>
    </ol>




</dd>
    <dt>
    <a name = "Heuristics.DIAGONAL"></a>
    <strong>Heuristics.DIAGONAL&nbsp;(dx, dy)</strong>
    </dt>
    <dd>
    Diagonal distance.
 <br/>Evaluates as <code>distance = max(|dx|, abs|dy|)</code>

    <h3>Parameters:</h3>
    <ul>
      <li><span class="parameter">dx</span>
        <span class="types"><span class="type">int</span></span>
       the difference endX-startX</li>
      <li><span class="parameter">dy</span>
        <span class="types"><span class="type">int</span></span>
       the difference endY-startY</li>
    </ul>

    <h3>Returns:</h3>
    <ol>

          <span class="types"><span class="type">number</span></span>
        the distance from location <code>startX, startY</code> to location <code>endX, endY</code>
 <ul>
 <pre class="example">
 -- First method
 pathfinder:setHeuristic('DIAGONAL')<br/>
 -- Second method
 local Distance = require ('jumper.core.heuristics')
 pathfinder:setHeuristic(Distance.DIAGONAL)
 </pre></ul>
    </ol>




</dd>
    <dt>
    <a name = "Heuristics.CARDINTCARD"></a>
    <strong>Heuristics.CARDINTCARD&nbsp;(dx, dy)</strong>
    </dt>
    <dd>
    Cardinal/Intercardinal distance.
 <br/>Evaluates as <code>distance = min(dx, dy)*squareRoot(2) + max(dx, dy) - min(dx, dy)</code>

    <h3>Parameters:</h3>
    <ul>
      <li><span class="parameter">dx</span>
        <span class="types"><span class="type">int</span></span>
       the difference endX-startX</li>
      <li><span class="parameter">dy</span>
        <span class="types"><span class="type">int</span></span>
       the difference endY-startY</li>
    </ul>

    <h3>Returns:</h3>
    <ol>

          <span class="types"><span class="type">number</span></span>
        the distance from location <code>startX, startY</code> to location <code>endX, endY</code>
 <ul>
 <pre class="example">
 -- First method
 pathfinder:setHeuristic('CARDINTCARD')<br/>
 -- Second method
 local Distance = require ('jumper.core.heuristics')
 pathfinder:setHeuristic(Distance.CARDINTCARD)
 </pre></ul>
    </ol>




</dd>
</dl>


</div> <!-- id="content" -->
</div> <!-- id="main" -->
<div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.3</a></i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>
</html>
